function Game (el){
    this.el = document.querySelector(el)
    this.t = null
    this.map=new Map(this.el)
    this.food=new Food(this.el)
    this.snake=new Snake(this.el)


}

Game.prototype.start=function(){
    this.t=setInterval(()=>{
        this.snake.move()

        let snakeX = this.snake.snakeobj[0].x*20
        let snakeY = this.snake.snakeobj[0].y*20
        let foodX = this.food.foodX
        let foodY = this.food.foodY

        if(snakeX == foodX&& snakeY == foodY){

            let last = this.snake.snakeobj[this.snake.snakeobj.length - 1]

            this.snake.snakeobj.push({
                x: last.x, 
                y : last.y, 
                color: last.color, 
                el:null
            })
            this.snake.create()
        }

            
        // this.eatFood()
       
    },150)
    this.keyEvent()
}

Game.prototype.stop=function(){
    clearInterval(this.t)
}

Game.prototype.keyEvent = function(){
document.addEventListener('keydown',(e)=>{
    e =e || window.event
    switch (e.keyCode) {
            case 38:
                this.snake.direction = 'top'
                break;
            case 40:
                this.snake.direction = 'bottom'
                break;
            case 37:
                if (this.snake.direction == 'right') {
                    alert('游戏结束')
                }
                this.snake.direction = 'left'
                break;
            case 39:
                this.snake.direction = 'right'
                break;
            default:
                break;
    }
})
}